package com.chlp.core.framework;

import com.chlp.core.framework.filter.HttpLoggingFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author 陈礼鹏
 * @date 2020/1/16 17:23
 */
@SpringBootApplication
@MapperScan("com.chlp.core.framework.dao")
@ComponentScan(basePackages = {"com.chlp.*"})
@EnableConfigurationProperties
public class FrameworkApplication {

	public static void main(String[] args) {
		SpringApplication.run(FrameworkApplication.class, args);
	}

	@Bean
	@ConditionalOnProperty(name = "cafe.enable.interface.filterLog", havingValue = "true")
	public FilterRegistrationBean<HttpLoggingFilter> httpLoggingFilter() {
		FilterRegistrationBean<HttpLoggingFilter> registration = new FilterRegistrationBean<>();
		// 添加过滤器
		registration.setFilter(new HttpLoggingFilter());
		// 设置过滤路径，/*所有路径
		registration.addUrlPatterns("/*");
		// 设置优先级
		registration.setName("httpLoggingFilter");
		// 设置优先级
		registration.setOrder(2);
		return registration;
	}

}